var mySwiper = new Swiper('.swiper1', {
    autoplay: 5000,//可选选项，自动滑动
    pagination: '.swiper-pagination',
    paginationClickable: true,
    paginationBulletRender: function (swiper, index, className) {
        return '<span class="' + className + '"></span>';
    }
})
var mySwiper = new Swiper('.swiper2', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    paginationBulletRender: function (swiper, index, className) {
        return '<span class="' + className + '"></span>';
    }
})
ajaxreq('/alldata', {}, function (data) {
    console.log(data);
    // for (let i = 0; i < data[0].length; i++) {
    //     $('.barNav span:eq(' + i + ')').html(data[0][i].cat_name).attr('cateID', i + 1);
    // }
    for (let i = 0; i < data[1].length; i++) {
        $('.col-lg-3:eq(' + i + ')').attr('goodID', data[1][i].goods_id)
        $('.tradeName:eq(' + i + ')').find('p:eq(0)').html(data[1][i].goods_name);
        $('.tradeName:eq(' + i + ')').find('p:eq(1)').html(data[1][i].goods_desc);
        $('.allImg:eq(' + i + ')').find('img').prop('src', data[1][i].goods_image);
        if (data[1][i].is_hot == 1) {
            $('.ad:eq(' + i + ')').css('background', 'url("../../images/lyjimg/hot.png") no-repeat');
        }
    }
    catesend(data[2], '.fruit');
    catesend(data[3], '.sea');
    catesend(data[4], '.meat');
    catesend(data[5], '.fast');
    $('.allType .aImg,.Hot .row>div').click(function () {
        localStorage.setItem('goodID', $(this).attr('goodID'));
        location.href = '/shopxq';
    })
    $('.Info i').click(function () {
        if (!localStorage.getItem('userID')) {
            $('#myModal').modal({
                remote: "/alert"
            });
        } else {
            $('#myModal').modal({
                remote: "/pay"
            });
        }
    })
})
function catesend(arr, partent) {
    for (let i = 0; i < arr.length; i++) {
        $('<div></div>').html('<div class="aImg"><img src="" alt=""></div><div class="Info"><h4></h4><span></span><p><span></span><s></s><i class="iconfont icon-gouwuche"></i></p></div>').appendTo($(partent + ' .allType'));
        $(partent + ' .allType>div:eq(-1) .aImg img').prop('src', arr[i].goods_image);
        $(partent + ' .allType>div:eq(-1) .aImg').attr('goodID', arr[i].goods_id);
        $(partent + ' .allType>div:eq(-1) h4').html('￥' + arr[i].goods_name);
        $(partent + ' .allType>div:eq(-1) .Info>span').html('￥' + arr[i].goods_desc);
        $(partent + ' .allType>div:eq(-1) .Info p span').html('￥' + arr[i].shop_price);
        $(partent + ' .allType>div:eq(-1) .Info p s').html('￥' + arr[i].shop_mprice);
    }
}
var curTime = new Date();
var num = 5 - curTime.getDay();
var actFri;
if (curTime.getDay() < 5) {
    actFri = new Date().setDate(curTime.getDate() + num);
} else {
    if (num == 0) {
        $('.lastTime span,.timer span:eq(0)').html('00');
    } else {
        actFri = new Date().setDate(curTime.getDate() + num + 7);
    }
}
var iTimer = setInterval(function () {
    var cTime = new Date();
    var Time = Math.floor((actFri - cTime) / 1000);
    var iD = Math.floor(Time / 86400);
    var iH = Math.floor((Time % 86400) / 3600);
    var iM = Math.floor((Time % 3600) / 60);
    var iS = Math.floor(Time % 60);
    $('.timer span:eq(0)').html(iD);
    $('.lastTime span:eq(0)').html(iH);
    $('.lastTime span:eq(1)').html(iM);
    $('.lastTime span:eq(2)').html(iS);
    if (Time <= 0) {
        clearInterval(iTimer);
    }
}, 1000);
